<html>
<head>
<meta charset="utf-8">
<title>某地对行业的统计</title>
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="js/common.js"></script>
<script type="text/javascript" src="js/handlebars-min-1.3.0.js"></script>

<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div id="" class="statistics"></div>
<!-- 模版引擎 -->
<script id="categorystart" type="text/x-handlebars-template">
{{#each class_Name}}
    <div class={{cla}}>
        <h1><em></em>各行业<b>{{name}}</b></h1>
        <ul></ul>
    </div>
{{/each}}
</script>

<script>
$(document).ready(function(){
    Handlebars.registerHelper('name', function() {
        return new Handlebars.SafeString(this.name);
    });
    Handlebars.registerHelper('cla', function() {
        return new Handlebars.SafeString(this.cla);
    })

    showBusiness();
    function showBusiness(){
        var $categorystart = $('#categorystart').html(),
            template = Handlebars.compile($categorystart);
        $('.statistics').html(template(location_category));
    }
})
</script>

<script>

jQuery.ajax({
    type:'get',
    url:apiURL+'location_categorystat',
    data:{
        province_code:29,
        sign:key
    },
    dataType : 'jsonp',
    async:false,
    jsonp: "callback",
    jsonpCallback:"dataList",
    success : function (myData) {

        var ismydata = myData.data,
            shengfendaima = ismydata.province_code;
        console.log(ismydata);


        function shopnumdict_percent (){
            var dataCodeName = ismydata.shopnumdict_percent;
            if (dataCodeName.length > 0) {
                
                var str = '';
                for (var i = 0; i < dataCodeName.length; i++) {
                    var hangyedaima = dataCodeName[i].category_code,
                        baifenbi = dataCodeName[i].percent,
                        hangye = hangyeNum[hangyedaima];

                    str += '<li><i>'+hangye + '</i>百分比：<span>'+toPercent(baifenbi)+'</span></li>';
                };
                $('.shopnumdict_percent').children('ul').append(str) ;
                console.log(baifenbi);
            } 
        }

        function totalsalesdict_percent (){
            var dataCodeName = ismydata.totalsalesdict_percent;
            if (dataCodeName.length > 0) {
                
                for (var i = 0; i < dataCodeName.length; i++) {
                    var hangyedaima = dataCodeName[i].category_code,
                        baifenbi = dataCodeName[i].percent,
                        hangye = hangyeNum[hangyedaima],
                        str = '';

                        xiaoshoue_per_c[parseInt(hangyedaima)] = baifenbi;

                    str += '<li><i>'+hangye + '</i>百分比：<span>'+toPercent(baifenbi)+'</span></li>';
                    $('.totalsalesdict_percent').children('ul').append(str) ;
                };
                    console.log(xiaoshoue_per_c.sort());
                    console.log('002是：'+xiaoshoue_per_c[002]);
                
                console.log(baifenbi);
            } 
        }


console.log(xiaoshoue_per_c);


        function salesnumdict (){
            var dataCodeName = ismydata.salesnumdict;
            if (dataCodeName.length > 0) {
                
                var str = '',hangye = '';
                for (var i = 0; i < dataCodeName.length; i++) {
                    var hangyedaima = dataCodeName[i].category_code,
                        zongshu = dataCodeName[i].count,
                        hangye = hangyeNum[hangyedaima];

                    str += '<li><i>'+hangye + '</i>销量：<span>'+zongshu+'</span>件</li>';
                };
                $('.salesnumdict').children('ul').append(str) ;
                console.log(zongshu);
            } 
        }

        function totalsalesdict (){
            var dataCodeName = ismydata.totalsalesdict;
            if (dataCodeName.length > 0) {
                
                var str = '',hangye = '';
                for (var i = 0; i < dataCodeName.length; i++) {
                    var hangyedaima = dataCodeName[i].category_code,
                        jine = dataCodeName[i].sold_money_week,
                        hangye = hangyeNum[hangyedaima];

                    str += '<li><i>'+hangye + '</i>金额：<span>'+jine+'</span>元</li>';
                };
                $('.totalsalesdict').children('ul').append(str) ;
                console.log(jine);
            } 
        }
        function salesnumdict_percent (){
            var dataCodeName = ismydata.salesnumdict_percent;
            if (dataCodeName.length > 0) {
                
                var str = '',hangye = '';
                for (var i = 0; i < dataCodeName.length; i++) {
                    var hangyedaima = dataCodeName[i].category_code,
                        baifenbi = dataCodeName[i].percent,
                        //baifenbi = Math.round(parseFloat(dataCodeName[i].percent)*10000)/100.00,
                        hangye = hangyeNum[hangyedaima];

                    str += '<li><i>'+hangye + '</i>百分比：<span>'+toPercent(baifenbi)+'</span></li>';
                };
                $('.salesnumdict_percent').children('ul').append(str) ;
                console.log(baifenbi);
            } 
        }  
        function shopnumdict (){
            var dataCodeName = ismydata.shopnumdict;
            if (dataCodeName.length > 0) {
                
                var str = '',hangye = '';
                for (var i = 0; i < dataCodeName.length; i++) {
                    var hangyedaima = dataCodeName[i].category_code,
                        zongshu = dataCodeName[i].count,
                        hangye = hangyeNum[hangyedaima];

                    str += '<li><i>'+hangye + '</i>总数：<span>'+zongshu+'</span>家</li>';
                };
                $('.shopnumdict').children('ul').append(str) ;
                console.log(zongshu);
            } 
        }
        if (myData.code===1200) {
            shopnumdict_percent();
            totalsalesdict_percent();
            salesnumdict();
            totalsalesdict();
            salesnumdict_percent();
            shopnumdict();
            shengfen = shengfenNum[shengfendaima];

            $('.statistics').find('em').text(shengfen+'省');

        } else{
            console.log('请刷新！');
        };
    },
    error : function (){
        alert('服务器故障！');
    }
});

function bubbleSort(transB){//对数组冒泡排序,变成从小到大排列的数组
    //console.log(transB.length);
    var temp;//先定义缓存
    for(var i=0;i<transB.length-1;i++){//一共比较n-1趟
        for(var j=0;j<transB.length-i-1;j++){//对当前无序区transB[i..j]自左向右扫描
            if(transB[j][0][0]>transB[j+1][0][0]){//交换
                temp=transB[j];
                transB[j]=transB[j+1];
                transB[j+1]=temp;
            }
        }
    }
return transB;
};
//bubbleSort(); //调用冒泡，对转录本排序

</script>
</body>
</html>